<!--
 * @Author: Zeratul
 * @Date: 2020-08-27 17:37:50
 * @LastEditTime: 2020-08-28 14:54:47
 * @FilePath: \sz-h5-2003-react-mobile\zhangminhui\eleme-react\chatServer\socketIOClient.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
      *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 400px;
            height: 550px;
            margin:50px auto;
            border:1px solid #ccc;
            position: relative;
        }
        .top{
            position: absolute;
            top:20px;
            left:20px;
            right:20px;
            bottom:80px;
            overflow: auto;
        }
        .bottom{
            position: absolute;
            bottom:20px;
            left:20px;
            right:20px;
        }
        #message{
            width: 300px;
            height: 30px;
            border:1px solid #ccc;
            line-height: 30px;
            float: left;
            padding-left:10px;
            box-sizing: border-box;
        }
        #send{
            width: 50px;
            float:right;
            height: 30px;
        }
        .row{
            line-height: 35px;
        }
    </style>
    <script src="./node_modules/socket.io-client/dist/socket.io.js"></script>
    <script src="./jquery-1.12.4.js"></script>
</head>

<body>
    <div class="box">
        <div class="top">
            
        </div>
        <div class="bottom">
            <input type="text" id="message">
            <input type="button" value="发送" id="send">
        </div>
    </div>
    <script>
        var socket = io('http://175.24.122.212:7777');
        socket.on('login',"商家")
        var count = 0;
        socket.emit('userLogin',{username:'商家'});
        socket.on('msg-from-server',function(data){
            count++;  
            $('.top').append('<div class="row">'+data+'</div>');
            $('.top').scrollTop(count*35);
        })

        $('#send').click(function(){
            socket.emit('msg-from-client',{username:'商家',msg:$('#message').val()});
            $('#message').val('')
        })

        $('#message').keyup(function(e){
            if(e.keyCode==13){
                socket.emit('msg-from-client',{username:'商家',msg:$('#message').val()});
                $('#message').val('')
            }
        })
    </script>
</body>

</html>